package top.dreamcenter.ai.llm.llmchat.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.dreamcenter.ai.common.entity.RetResult;
import top.dreamcenter.ai.llm.llmchat.entity.SimpleQuesEntity;


@RestController
@RequestMapping("/simple")
public class SimpleQuesController {


    @Resource(name = "toolCallClient")
    private ChatClient toolCallClient;

    @Resource(name = "ragRetrieveClient")
    private ChatClient ragRetrieveClient;

    @GetMapping("singleEntity")
    public RetResult<SimpleQuesEntity> singleEntity(Long uid, String question) {

        try {
            SimpleQuesEntity entity = ragRetrieveClient.prompt()
                    .system("对于version结果，取{version}")
                    .system(spec -> spec.param("version", "v1.0"))
                    .advisors(
                            spec -> spec.param(AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY, uid)
                    )
                    .user(question)
                    .call()
                    .entity(SimpleQuesEntity.class);
            return RetResult.ok(entity);
        } catch (Exception e) {
            return RetResult.fail(e.getMessage());
        }

    }



    @GetMapping("singleCall")
    public RetResult<String> singleCall(String question) {
        try {
            String res = toolCallClient.prompt()
                    .user(question)
                    .call()
                    .content();
            return RetResult.ok(res);
        } catch (Exception e) {
            return RetResult.fail(e.getMessage());
        }
    }

}
